// pages/particulars/particulars.js
import API from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    reviews: [],
    showhidden: true,
    detail: [],
    duration: 300,
    swiperCurrent: 0,
    chat: true,
    isFocus: false,
    commentCon: '',
    footerIslike: false,
    pid: 0,
    id: 0,
    level: 0
  },
  //轮播图的切换事件  
  swiperChange: function (e) {
    console.log(e);
    this.setData({
      swiperCurrent: e.detail.current   //获取当前轮播图片的下标
    })
  },
  // 进入圈子详情
  circle: function () {
    wx.navigateTo({
      url: '/pages/circle/circle',
    })
  },
  //点击图片切换  
  chuangEvent: function (e) {
    console.log(e);
    this.setData({
      swiperCurrent: e.currentTarget.id
    })
  },
  more: function () {
    this.setData({
      chat: (!this.data.chat)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.setData({
      id: id
    })

    this.getDetail()
    this.getAllComment()
  },

  onShow: function () {

  },
  getDetail() {
    var data = {
      circleid: this.data.id
    }
    API.getdetail(data).then(res => {
      if (res.ret == 0) {
        this.setData({
          detail: res.data
        })
      }
    })
  },
  // 获取评论
  getAllComment() {
    var data = {
      circleid: this.data.id
    }
    API.getreviews(data).then(res => {
      console.log(res);
      if (res.ret == 0) {
        if(res.data == ""){
         var showhidden = false;
        }
          this.setData({
          reviews: res.data,
          showhidden:showhidden
        })
      }
    })
  },
  // 查看全部回复
  lookAllReply(e) {
    wx.navigateTo({
      url: '/pages/allReply/allReply?allId='+e.currentTarget.dataset.id+'&questionid='+this.data.id+'&from=1',
    })
  },
    // 回复
    reply (e) {
      var dataset = e.currentTarget.dataset
      console.log(dataset)
      this.setData({
        commentCon:'回复@'+dataset.nickname+':',
        level: 1,
        pid:dataset.id,
        isFocus:true
      })
  
    },
  footerLike(e) {
    var footerIslike = this.data.footerIslike
    var likeNum = e.currentTarget.dataset.zancount
    var status = 0
    if (footerIslike) {
      likeNum--
      status = 0
    } else {
      likeNum++
      status = 1
    }
    footerIslike = !footerIslike
    var data = {
      questionid: this.data.detailId,
      status: status
    }
    API.like(data).then(res => {
      if (res.ret == 0) {
        this.getDetailData(this.data.detailId)
      }
    })

    this.setData({
      footerIslike: footerIslike,
      zancount: likeNum
    })
  },
  getfooterComment(e) {
    this.setData({
      commentCon: e.detail.value
    })

  },
  footerComment() {
    if (this.data.commentCon == '') {
      wx.showModal({
        title: '',
        content: '请输入评论'
      })
      return
    }
    var data = {
      content: this.data.commentCon,
      pid: this.data.pid,
      caid: this.data.id,
      level: this.data.level
    }
    API.addquanzireview(data).then(res => {
      if (res.ret == 0) {
        wx.showToast({
          title: '评论成功',
          icon: 'success',
          duration: 2000
        })
        setTimeout(() => {
          this.getDetail()
          this.getAllComment()
        }, 2000)
        this.setData({
          commentCon: '',
          isFocus: false
        })
      }
    })
  },
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})